// pages/jdjb/jdjb.js
const db = wx.cloud.database()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        array1: ['AAAAA', 'BBBBB', 'CCCCCC'],
        objectArray1: [
            { id: 0, name: 'AAAAA' },
            { id: 1, name: 'BBBBB' },
            { id: 2, name: 'CCCCCC' },
        ],
        array2: ['10:00-12:00', '12:30-14:30', '15:00-17:00', '17:30-19:30'],
        objectArray2: [
            { id: 0, name: '10:00-12:00' },
            { id: 1, name: '12:30-14:30' },
            { id: 2, name: '15:00-17:00' },
            { id: 3, name: '17:30-19:30' },
        ],
        index1: '0',
        index2: '0',
        radio: '',
        input1: '',
        input2: '',
        picker1: '',
        picker2: '',
        index1: '0',
        index2: '0',
        phone: '',
        radio2: '',
        input3: '',
    },

    bindPickerChange1: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index1: e.detail.value,
            picker1: e.detail.value
        })
    },
    bindPickerChange2: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index2: e.detail.value,
            picker2: e.detail.value
        })
    },
    formSubmit(e) {
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
        let phone = wx.getStorageSync('user')
        this.setData({
            radio: e.detail.value.radio,
            input1: e.detail.value.input1,
            input2: e.detail.value.input2,
            phone: phone._id
        })
        db.collection('report').add({
            data: {
                phone: this.data.phone,
                report_type: this.data.radio,
                report_cg: this.data.picker1,
                report_time: this.data.picker2,
                report_cause: this.data.input1,
                report_seat: this.data.input2,
                _createTime: Date.parse(new Date())
            },
            success: (res => {
                wx.showToast({
                    title: '举报成功!',
                    icon: 'success'
                })
                setTimeout(function () {
                    wx.switchTab({
                        url: '../index/index',
                    })
                }, 1000)
            })
        })
    },
    formSubmit2(e) {
        console.log('form发生了submit事件，携带数据为：', e.detail.value)
        let phone = wx.getStorageSync('user')
        this.setData({
            radio: e.detail.value.radio,
            input: e.detail.value.input,
            phone: phone._id
        })
        db.collection('Feedback').add({
            data: {
                phone: this.data.phone,
                Feedback_type: this.data.radio,
                yj: this.data.input,
                Feedback_result: 0,
                _createTime: Date.parse(new Date())
            },
            success: (res => {
                wx.showToast({
                    title: '提交成功!',
                    icon: 'success'
                })
                setTimeout(function () {
                    wx.switchTab({
                        url: '../index/index',
                    })
                }, 1000)
            })
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let phone = wx.getStorageSync('user')
        this.setData({
            phone: phone._id,
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})